<template>
    <!-- 添加或修改对话框  v-if="dataForm.fileType === 12"-->
    <el-dialog title="归属转移" width="500px" :visible.sync="visible" :close-on-click-modal="false" >
      
        <el-form size="medium" label-position="right"  label-width="120px" >
          <el-form-item label="客户姓名：" prop="realNameOrMobile">
            <el-input v-model="projectRow.realName" clearable class="filter-item" disabled/>
          </el-form-item>
          <el-form-item label="身份证：" prop="idCardNo">
               <el-input v-model="projectRow.idCardNo" clearable class="filter-item" disabled/>
          </el-form-item>
          <el-form-item label="转移对象：" prop="loanType">
            <el-select v-model="projectRow.transferObj" placeholder="请选择" style="min-width:100%;" @change="change">
              <el-option v-for="(item) in permissionList" value-key="userId" :key="item.userId" :value="item.userId" :label="item.displayName"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="" prop="loanType" label-width="50px">
            注：转移成功后，该客户将属于转移对象名下，请谨慎操作。
          </el-form-item>
        </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small"  @click="close">取消</el-button>
        <!-- <el-button size="mini" v-if="dialogStatus=='create'" type="primary" @click="createData">确定</el-button> -->
        <el-button type="primary" size="small" @click="projectTransfer">确定</el-button>
      </div>
    </el-dialog>
</template>


<script>
  import { permissionList,projectTransfer } from '@/api/project'

export default {
  name: 'add',
  // 接受父组件的值
  props: {
      projectId:undefined,
     dialogVisible:{
       type: Boolean,
       default:false
     },
     row:{
       type:Object,
       default:{
         realName: undefined,
         inCardNo:undefined,
         transferObj: undefined
       }
     }
    },
  data() {
    return {
      list: undefined,
      visible:false,
      projectRow: {
         realName: undefined,
         inCardNo:undefined,
         transferObj: undefined
      },
      permissionList:[]
    }
  },
  watch: {
    "row":function(val){
      this.projectRow = val
    },
    "dialogVisible":function(val) {
      this.visible = val
    }
  },
  created() {
    this.getPermissionList()
    
  },
  methods: {
    close() {
      this.$emit('close')
    },  
    getPermissionList() {
      permissionList()
        .then((res) => {
          let data = res.data;
          let permissionList = this.permissionList
          let list = data.map(item => {
            item.userId = item.userId.toString(); 
            return item
          }) 
          this.permissionList = [...permissionList,...list]
        })
        .catch(() => {
           this.permissionList = []
        })
    },
    change(value) {
      let list = this.permissionList;
      let createName;
      list.map(item => {
        if(item.userId == value) {
          createName = item.dictTypeName
        }
      })
      this.projectRow.transferObj = value;
    },
    projectTransfer() {
      if(this.projectRow.transferObj == undefined || this.projectRow.transferObj == ""){
        this.$message.error('请选择转移对象')
        return false
      }
      projectTransfer({projectId:this.projectId,creatorId:this.projectRow.transferObj}).then(res => {
        if(res.data) {
          this.$emit('close')
          this.$emit("getList");
        }
      })
    }
  }
}
</script>

<style scoped>
.parentColl >>> .el-collapse-item__header{
  min-height: 95px;
  font-size: 20px;
  font-weight: 1000;
  padding:20px;
}
</style>
